package pyrachnid.view.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JOptionPane;

import pyrachnid.ctrl.Simulator;
import pyrachnid.view.component.MapFileChooser;

/**
 * @author zygou
 *
 */
public class NewMapListener implements ActionListener {

	private Simulator _simulator;
	
	public NewMapListener(Simulator p_sim) {
		_simulator = p_sim;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		MapFileChooser mfc = new MapFileChooser(_simulator);
		if(mfc.showOpenDialog(_simulator.getMainWindow()) == JOptionPane.OK_OPTION){
			String mapPath = new File(".").toURI().relativize(mfc.getSelectedFile().toURI()).getPath();
			_simulator.getSenario().setMapPath(mapPath);
			_simulator.loadScenar(_simulator.getSenario());
		}
	}

}
